<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <input type="date">
    <script>
        // 1
        var obj = {
            a: 10,
            b: this.a + 10,
            fn: function() {
                return this.a;
            }
        }
        console.log(obj.b); //NaN
        console.log(obj.fn()); //10
        // 2
        var a = 20;
        var obj = {
            a: 10,
            getA: function() {
                return this.a;
            }
        }
        console.log(obj.getA()); //10
        var test = obj.getA;
        console.log(test()); //20
        // 3
        var a = 5;

        function fn1() {
            var a = 6;
            console.log(a); //6
            console.log(this.a); //5
        }

        function fn2(fn) {
            var a = 7;
            fn();
        }
        var obj = {
            a: 8,
            getA: fn1
        }
        fn2(obj.getA);
        // 4
        function fn() {
            // 'use strict';
            var a = 1;
            var obj = {
                a: 10,
                c: this.a + 20
            }
            return obj.c;
        }
        console.log(fn()); //报错。Cannot read property 'a' of undefined。在严格模式下，禁止this关键字指向全局对象。去掉use strict  打印出25
        // 5
        function Person(name, age) {
            this.name = name;
            this.age = age;
            console.log(this); //Person{name:"test",age:18}
        }
        Person.prototype.getName = function() {
            console.log(this); ////Person{name:"test",age:18}
        }
        var p1 = new Person('test', 18);
        p1.getName();
        // 6
        var obj = {
            foo: "test",
            fn: function() {
                var mine = this;
                console.log(this.foo); //mine.foo   test
                console.log(mine.foo); //mine.foo    test
                (function() {
                    console.log(this.foo); //window  f foo(){console.log(this.a)}
                    console.log(mine.foo); //test
                })();
            }
        };
        obj.fn();
        // 7
        function foo() {
            console.log(this.a); //3  2  4
        }
        var a = 2;
        var o = {
            a: 3,
            foo: foo
        };
        var p = {
            a: 4
        };
        o.foo();
        (p.foo = o.foo)();

        p.foo = o.foo;
        p.foo();
        // 8
        function foo() {
            console.log(this.a);
        }
        var obj1 = {
            a: 3,
            foo: foo
        };
        var obj2 = {
            a: 5,
            foo: foo
        };
        obj1.foo(); //3
        obj2.foo(); //5

        obj1.foo.call(obj2); //5
        obj2.foo.call(obj1); //3
        // 9
        function test(arg) {
            this.x = arg;
            return this;
        }
        var x = test(5);
        var y = test(6);
        console.log(x.x); //undefined
        console.log(y.x); //6
        // 10
        var obj = {
            data: [1, 2, 3, 4, 5],
            data2: [1, 2, 3, 4, 5],
            fn: function() {
                console.log("-----test-----"); //-----test-----
                console.log(this); //window  对象
                return this.data.map(function(item) {
                    console.log(this);
                    return item * 2;
                })
            },
            fn2: function() {
                console.log("-----test2-----"); //-----test-----
                console.log(this);

                return this.data2.map(item => {
                    console.log(this); //window  对象
                    return item * 2; //[2,4,6,8,10]
                })
            }
        };
        obj.fn();
        obj.fn2();
    </script>
</body>

</html>